﻿using Gasgoo.ShareLibrary.Framework.Global;
using Orleans.Runtime;
using System;

namespace Gasgoo.ShareLibrary.Framework.iDataProvider
{
    //public interface AbstractDataEntity
    //{
    //    /// <summary>
    //    /// 主键
    //    /// </summary>
    //    string PrimaryKey { get; set; }

    //    /// <summary>
    //    /// 创建时间
    //    /// </summary>
    //    DateTime CreateDate { get; set; }

    //    /// <summary>
    //    /// 修改时间
    //    /// </summary>
    //    DateTime ModifyDate { get; set; }

    //    /// <summary>
    //    /// 是否删除
    //    /// </summary>
    //    bool IsDelete { get; set; }
    //}

    public abstract class AbstractDataEntity
    {
        private string _provider;

        /// <summary>
        /// 主键信息
        /// </summary>
        public string PrimaryKey { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateDate { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime ModifyDate { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool IsDelete { get; set; }

        /// <summary>
        /// 获取提供商名称
        /// </summary>
        /// <returns></returns>
        public string GetProviderName() => _provider;

        /// <summary>
        /// 设置提供商名称
        /// </summary>
        /// <param name="provider"></param>
        public void SetProviderName(string provider) { this._provider = provider; }

        /// <summary>
        /// 获取IDataStorageProvider实例
        /// </summary>
        /// <returns></returns>
        public IDataStorageProvider GetDataStorageProvider()
        {
            var serviceProvider = ServiceManage.GetServiceProvider(Constants.SILO_HOST_SERVICE_PROVIDER);
            var dataProviderName = this.GetProviderName();
            return serviceProvider.GetRequiredServiceByName<IDataStorageProvider>(dataProviderName);
        }
    }
}
